// createRouter: 创建路由实例对象
// createWebHistory: 创建 history 模式的路由
import { createRouter, createWebHistory } from 'vue-router'

import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/CheckOut/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue' 
import Member from '@/views/Member/index.vue'
import MemberInfo from '@/views/Member/components/UserInfo.vue'
import MemberOrder from '@/views/Member/components/UserOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      component: Layout,
      children: [
        {
          // path 为空 是默认路由, 默认展示这个组件
          path:'',
          component: Home
        },
        // 一级分类页
        {
          // 配置占位符 id
          path:'category/:id',
          component:Category
        },
        // 二级分类页
        {
          path:'category/sub/:id',
          name:'subCategory',
          component:SubCategory
        },
        // 详情页
        {
          path:'detail/:id',
          component:Detail
        },
        // 购物车列表页
        {
          path:'cartlist',
          component:CartList
        },
        // 订单结算页
        {
          path:'checkout',
          component:CheckOut
        },
        // 创建订单页
       {
          path: 'pay',
          component:Pay
       },
        // 支付后的回调页面  
        {
          path:'paycallback',
          component:PayBack
        },
        // 会员中心页
        {
          path:'/member',
          component:Member,
          children:[
            {
              // 默认显示 memberinfo 组件内容, 记得 routerlink那里也要改
              path:'',
              component:MemberInfo
            },
            {
              path:'order',
              component:MemberOrder
            }
          ]
        }
      ]
    },
    {
      path:'/login',
      component:Login
    }

  ],
  // 路由滚动行为定制 -- 当路由切换时, top为 0
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
